package com.pbc.gmp.commons.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by UPC on 2017/5/10.
 */
public class permissionBitUtil {


    public static  List<Integer> GetBitlist(String acl) {

        List<Integer> acllist = new ArrayList();
        String binaryStr = Integer.toBinaryString(Integer.parseInt(acl));
        StringBuilder sb = new StringBuilder(binaryStr);
        char[] b=sb.reverse().toString().toCharArray();
        for(Integer i=0;i<=b.length-1; i++)
        {
            if(b[i]=='1')
            {
                acllist.add(i+1);
            }
        }
        return  acllist;
    }
    /**
     * 检查在某个位置是否可以访问
     * @param index
     * @return
     */


    public static boolean checkPermission(int index,int aclState) {

        int num = aclState&index;
        return num>0;
    }
    public static boolean checkPermission(int index,String aclState) {
        String[] array = aclState.split("\\+");
        int permissionBit=0;
        if(array.length > 2) {
            permissionBit = Integer.valueOf(array[2]);
        }
        int num = permissionBit&index;
        return num>0;
    }



}
